package com.tsingtree.modular.service.impl;

import com.tsingtree.modular.entity.NanGameTiger;
import com.tsingtree.modular.mapper.NanGameTigerMapper;
import com.tsingtree.modular.model.params.NanGameTigerParam;
import com.tsingtree.modular.model.result.NanGameTigerResult;
import  com.tsingtree.modular.service.NanGameTigerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.roses.core.util.ToolUtil;
import java.io.Serializable;


/**
 * <p>
 * 老虎机 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2025-05-30
 */
@Service
public class NanGameTigerServiceImpl extends ServiceImpl<NanGameTigerMapper, NanGameTiger> implements NanGameTigerService {

    @Override
    public void add(NanGameTigerParam param){
        NanGameTiger entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanGameTigerParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(NanGameTigerParam param){
        NanGameTiger oldEntity = getOldEntity(param);
        NanGameTiger newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public NanGameTigerResult findBySpec(NanGameTigerParam param){
        return null;
    }

    @Override
    public List<NanGameTigerResult> findListBySpec(NanGameTigerParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(NanGameTigerParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(NanGameTigerParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private NanGameTiger getOldEntity(NanGameTigerParam param) {
        return this.getById(getKey(param));
    }

    private NanGameTiger getEntity(NanGameTigerParam param) {
        NanGameTiger entity = new NanGameTiger();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
